/*<div class="bx-list-box" id="widget">

</div>*/

/*
	recommend 推荐位数据 array
	ContentList 列表数据 array
*/
// 定义一个全局的
var widget1Config = {};
/*
	recommend     推荐位数据
	ContentList   列表项数据
	currentPage   当前页
*/
function widget1Init(recommend,ContentList,currentPage){

	widget1Config.recommend = recommend;
	widget1Config.ContentList = ContentList;
	//获取列表内容个数
	var listLength = ContentList.length;
	//获取推荐个数
	var recommendLength = recommend.length;
	//获取当前page
	widget1Config.page = currentPage?currentPage:0;
	//获取总页数
	widget1Config.totalPage = Math.ceil(listLength / 8);
	// 获取当前 推荐详细数据
	var currentRecommend = recommend[widget1Config.page%recommendLength];
	// 获取当前 列表数组
	var currentList = ContentList.slice(widget1Config.page * 8, widget1Config.page * 8 + 8);
	// 最后一页，补全8条数据
	currentList = currentList.length == 8?currentList:ContentList.slice(listLength - 8, listLength);

	var currentLeftList = currentList.slice(0, 2);
	var currentRightList = currentList.slice(2, 8);

	var leftSrc = widget1Config.page == 0?'../images/home/zuojiantou_1.png':'../images/home/xiangzuo.png';
	var rightSrc = widget1Config.page == widget1Config.totalPage-1?'../images/home/youjiantou_1.png':'../images/home/xiangyou.png';


	var str = "\
	<div class='list-box-widget' id='widgetTop'>\
		<div class='left_arrow'>\
			<img src='"+leftSrc+"'>\
		</div>\
		<div class='list-box-content' id='widgetContent'>\
			<div id='widgetContentx0' style='width: 50%;height: 100%;float: left;'>\
				<div class='ver_box_style' id='widgetContentx0y0' tabindex='-1' style='width: 100%;height: 66.66%;float: left;'>\
					<img src='"+currentRecommend.image+"'>\
					<p class='style1-con-des'>"+currentRecommend.description+"</p>\
				</div>\
				<div id='widgetContentx0y1' style='width: 100%;height: 33.33%;float: left;'>\
					<ul id='widgetContentx0y1ul' style='width: 100%;height: 100%;overflow: hidden;'>\
						"+createLi(currentLeftList,'50%','100%')+"\
					</ul>\
				</div>\
			</div>\
			<div id='widgetContentx1' style='width: 50%;height: 100%;float: left;'>\
				<ul id='widgetContentx1ul' style='width: 100%;height: 100%;overflow: hidden;'>\
					"+createLi(currentRightList,'50%','33.33%')+"\
				</ul>\
			</div>	\
		</div>\
		<div class='right_arrow'>\
			<img src='"+rightSrc+"'>\
		</div>\
	</div>\
	<div class='list-box-back'>\
		<span> "+(widget1Config.page+1)+" / "+widget1Config.totalPage+" </span>\
		<img src='../images/home/return.png'>\
	</div>"

	$("#widget1").html(str);

	setFocus("widgetContentx0y0");
}


function createLi(dataArray,width,height){

	var str = "";

	for(var i = 0; i < dataArray.length; i++){

		str += "<li class='ver_box_style' tabindex='-1' style='float:left;width:"+width+";height:"+height+";'><img src='"+dataArray[i].image+"'><p class='style1-con-des'>"+dataArray[i].description+" <span>"+dataArray[i].date+"</span></p></li>"
	}
	
	return str;
}

function widgetTop(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					onSelect(event,dom.parent(),dir);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
function widgetContent(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":

					if(widget1Config.page == 0){
						onSelect(event,dom.parent(),dir);
					}else{
						widget1Config.page = widget1Config.page - 1;
						widget1Init(widget1Config.recommend,widget1Config.ContentList,widget1Config.page);
					}

					break;
				case "right":

					
					if(widget1Config.page == widget1Config.totalPage-1){
						onSelect(event,dom.parent(),dir);
					}else{
						widget1Config.page = widget1Config.page + 1;
						widget1Init(widget1Config.recommend,widget1Config.ContentList,widget1Config.page);
					}

					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
function widgetContentx0(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					setFocus("widgetContentx1ul");
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
function widgetContentx1(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					setFocus("widgetContentx0y0");
					break;
				case "right":
					onSelect(event,dom.parent(),dir);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
function widgetContentx0y0(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					setFocus("widgetContentx0y1ul");
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					onSelect(event,dom.parent(),dir);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			window.location.href = hdLocation+"play.html";
			break;
	}
}
function widgetContentx0y1(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					setFocus("widgetContentx0y0");
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					setFocus("widgetContentx1ul",4);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}
function widgetContentx0y1ul(event,dom,dir){
	switch(event){
		case "MoveFocus":
			if(ulIsBorder(dom,dir,2,2)){

				onSelect(event,dom.parent().parent(),dir);

			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			window.location.href = hdLocation+"onDemandDetail.html";
			break;
	}
}
function widgetContentx1ul(event,dom,dir){
	switch(event){
		case "MoveFocus":
			if(ulIsBorder(dom,dir,2,6)){
				switch(dir){
					case "up":
						onSelect(event,dom.parent().parent(),dir);
					case "down":
						onSelect(event,dom.parent().parent(),dir);
						break;
					case "left":
						
						var index = dom.index();

						if(index == 4){
							setFocus("widgetContentx0y1ul",1);
						}else{
							onSelect(event,dom.parent().parent(),dir);
						}

						break;
					case "right":
						onSelect(event,dom.parent().parent(),dir);
						break;
				}
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			window.location.href = hdLocation+"onDemandDetail.html";
			break;
	}
}
function widget1(event,dom,dir){
	switch(event){
		case "MoveFocus":
			switch(dir){
				case "up":
					onSelect(event,dom.parent(),dir);
					break;
				case "down":
					onSelect(event,dom.parent(),dir);
					break;
				case "left":
					onSelect(event,dom.parent(),dir);
					break;
				case "right":
					onSelect(event,dom.parent(),dir);
					break;
			}
			break;
		case "Back":
			onSelect(event,dom.parent());
			break;
		case "Click":
			break;
	}
}